Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

java - JSF 2 : tag wrapper to encapsulate common attribute values? -


based on previous question how id of calling component in getter method? , here's idea want ask opinion :

there lots of duplicated code across jsf pages such these examples (notice repeating size , maxlength attribute) across components :

<h:inputtext label="#{msgs.userid}" id="userid" value="#{userbean.userid}"     required="true"     size="#{variableconfigbean.getsize(component.id)}"     maxlength="#{variableconfigbean.getmaxlength(component.id)}" /> <h:inputsecret label="#{msgs.password}" id="password" value="#{userbean.password}"     required="true"      size="#{variableconfigbean.getsize(component.id)}"     maxlength="#{variableconfigbean.getmaxlength(component.id)}" /> 

im thinking of :

  1. using composite component input text tag,
  2. hardcoding size , maxlength in implementation section of composite component,
  3. so dont have duplicate these stuffs everytime need use component.
  4. but i'll have open attributes in interface section of composite component

is idea ok, or perhaps there other better ways solve problem ?

you so. i've implemented in projects. adds (minor) overhead. particular purpose use facelets tag file instead of jsf composite component. it's not mandatory define attributes then. in particular case can refactor pretty duplicates if reuse bean property name id , key message bundle label.

e.g.

<my:input type="text" bean="#{userbean}" property="userid" required="true" /> <my:input type="secret" bean="#{userbean}" property="password" required="true" /> 

with following in facelets tag file:

<c:set var="id" value="#{not empty id ? id : property}" /> <c:set var="required" value="#{not empty required , required}" />  <c:choose>     <c:when test="#{type == 'text'}">         <h:inputtext id="#{id}"              label="#{msgs[property]}"             value="#{bean[property]}"              size="#{config.size(id)}"              maxlength="#{config.maxlength(id)}"              required="#{required}" />     </c:when>     <c:when test="#{type == 'secret'}">         <h:inputsecret id="#{id}"              label="#{msgs[property]}"             value="#{bean[property]}"              size="#{config.size(id)}"              maxlength="#{config.maxlength(id)}"              required="#{required}" />     </c:when>     <c:otherwise>         <h:outputtext value="unknown input type: #{type}" />     </c:otherwise>             </c:choose> 

i've implemented <h:outputlabel> before , <h:message> after makes refactoring more reasonable.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -