[jbossseam-issues] [JBoss JIRA] Closed: (JBSEAM-93) give a Component more than one DataModel

Gavin King (JIRA) jira-events at jboss.com
Tue Nov 21 04:22:47 EST 2006


     [ http://jira.jboss.com/jira/browse/JBSEAM-93?page=all ]

Gavin King closed JBSEAM-93.
----------------------------


> give a Component more than one DataModel
> ----------------------------------------
>
>                 Key: JBSEAM-93
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-93
>             Project: JBoss Seam
>          Issue Type: Feature Request
>          Components: Core
>    Affects Versions: 1.0 beta 1
>         Environment: normal
>            Reporter: ya xiang
>         Attachments: Component.java, DataModel2.java
>
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> sometimes I need place more than one DataModel in one component control object.
> but at present, Componenent can only do a single DataModel.
> can model DataModel annotation and Component let it support multiple DataModel.
> I have a simple solution without modified exist model and application, just add DataModel2 annotation. and remain origin DataModel and its usage.
> code as follows:
>    /**
>     * FIXME:added by xiangya
>     */
>    private Set<Field> dataModelFields = new HashSet<Field>();
>   public void inject(Object bean/*, boolean isActionInvocation*/)
>    {
>       injectMethods(bean/*, isActionInvocation*/);
>       injectFields(bean/*, isActionInvocation*/);
>       injectDataModelSelection(bean);
>       injectDataModels(bean);
>    }
>    public void outject(Object bean)
>    {
>       outjectMethods(bean);
>       outjectFields(bean);
>       outjectDataModel(bean);
>       outjectDataModels(bean);
>    }
>    
>    //TODO: submit;
>    private void injectDataModels(Object bean) {
> 	   Field selectionIndexField=null, selectionField=null;
> 	      for (Field field : dataModelFields)
> 	      {
> 	         DataModel2 dm = field.getAnnotation(DataModel2.class);
>              String name = toName(dm.value(), field);
>              javax.faces.model.DataModel dataModel = (javax.faces.model.DataModel)Contexts.getConversationContext().get(name);
>              if (dataModel!=null){
>                  if (dm.selectionIndex().length()>0){
>                 	 try{
>                 		 selectionIndexField =beanClass.getDeclaredField(dm.selectionIndex());
>                 		 log.info(selectionIndexField);
>                 		 selectionIndexField.setAccessible(true);
>                 		 setFieldValue(bean, selectionIndexField, name, dataModel.getRowIndex());
>                 	 }catch (NoSuchFieldException e) {
>     					log.info(String.format("can not found DataModelSelectionIndex %s in DataModel %s ", 
>     							dm.value(), dm.selectionIndex()));
>     				}
>                  }
>                  if (dm.selection().length()>0){
>                 	 try{
>                 		 selectionField = beanClass.getDeclaredField(dm.selection());
>                 		 log.info(selectionIndexField);
>                 		 selectionField.setAccessible(true);
>                 		 setFieldValue(bean, selectionField, name, dataModel.getRowData());
>                 	 }catch(NoSuchFieldException e){
>                 		 log.info(String.format("can not found DataModelSelection %s in DataModel %s", dm.value(), dm.selection()));
>                 	 }
>                  }
>              }
> 	      }
> 	
>    }
>    
>    private void outjectDataModels(Object bean) {
> 	   List list=null;
> 	   for(Field field: dataModelFields){
> 		   list = (List) getFieldValue(bean, field);
> 		   name = toName(field.getAnnotation(DataModel2.class).value(), field);
> 			 if (list!=null)
> 			 {
> 			    ListDataModel dataModel = new org.jboss.seam.jsf.ListDataModel(list);
> 			    Contexts.getConversationContext().set( name, dataModel );
> 			 }
> 			 else
> 			 {
> 			    Contexts.getConversationContext().remove(name);
> 			 }
> 	   }
>    }
>    //TODO: submit;
> oooh, maybe I should create a patch.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list