struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Lindholm <glindh...@yahoo.com>
Subject Re: Stumped on form field
Date Mon, 06 Apr 2009 12:38:16 GMT

You are missing a setDays(Integer i) in your action.
Or, change the textfield to "ruleDays".

<s:textfield key="ruleDays" size="4" />


Security Management wrote:
> 
> I cannot figure this out, days is never set, and the debug logging does
> not
> show up for setting days, but it does for name.  Anyone have any idea?
> 
> JSP page:
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <s:include value="/pages/common/jsps/header.jsp" />
> 
> <body>
> 	<div id='top_div'>
> 		<h1><s:text name="sc_title"/> <s:text
> name="sc_add_edit_rule_name"/></h1>
> 		<s:include value="/pages/common/jsps/menu.jsp" />
> 	</div>
> 	
> 	<div id='body_div'>
> 		<p><s:text name="sc_rule_days_description"/></p>
> 		<s:form action="saveRuleName" method="POST">
> 			<s:textfield key="ruleName" />
> 			<s:textfield key="days" size="4" />
> 			<s:select name="ruleTypes" multiple="true"
> list="allTypes" listKey="id" listValue="description" label="Person Types"
> value="selectedPersonTypes"/>
> 			<s:hidden name="ruleId"/>
> 			<s:url value="/pages/common/images/save.png"
> var="search_button"/>
> 			<s:submit type="image" src="%{search_button}"/>
> 		</s:form>
> 	</div>
> 	<s:include value="/pages/common/jsps/footer.jsp" />
> 
> The struts.xml snippet:
> <action name="saveRuleName"
> class="com.secmgmt.struts2.actions.scrounger.SaveRuleNameDaysTypes">
> 			<result
> name="success">/pages/scrounger/jsps/add-exceptions.jsp</result>
> </action>
> 
> The Java class:
> package com.secmgmt.struts2.actions.scrounger;
> 
> import com.secmgmt.struts2.base.SMCBaseAction;
> import com.secmgmt.interfaces.auth.IAuthProvider;
> import com.secmgmt.interfaces.people.providers.IPersonProvider;
> import com.secmgmt.interfaces.people.providers.IScroungerProvider;
> import com.secmgmt.interfaces.people.IScroungerRule;
> import com.secmgmt.interfaces.people.IPersonType;
> 
> import java.util.List;
> import java.util.ArrayList;
> import java.util.Iterator;
> import org.apache.log4j.Logger;
> 
> /**
>  * <code>IndexAction</code>
>  *
>  * @author Mike Baranski (mike@secmgmt.com)
>  */
> public class SaveRuleNameDaysTypes extends SMCBaseAction
> {
>     private static Logger l =
> Logger.getLogger(SaveRuleNameDaysTypes.class);
>     private IAuthProvider authProvider;
>     private IScroungerProvider sp;
>     private IPersonProvider ppp;
>     
>     private Long ruleId;
>     private Integer days;
>     private String ruleName;
> 
>     private IScroungerRule r;
> 
>     public IScroungerRule getRule()
>         {
>             return r;
>         }
> 
>     public void setRule(IScroungerRule r)
>         {
>             this.r = r;
>         }
> 
> // Set from the form
>     private List<Long> ruleTypes;
> 
>         // Converted from the form
>     private List<IPersonType> ruleIPersonTypes;
> 
>     public void setRuleDays(String i)
>         {
>             l.debug("Setting days: " + i);
>             try
> {
>                 this.days = new Integer(i);
>             }
>             catch(NumberFormatException e)
>             {
>                 l.error("Error parsing: " + e.toString());
>                 this.days = null;
>             }
>         }
> 
>     public void setRuleName(String n)
>         {
>             l.debug("Setting rule name: " + n);
>             this.ruleName = n;
>         }
> 
>     public String getRuleName()
>         {
>             return this.ruleName;
>         }
>     
>     public Integer getRuleDays()
>         {
>             return this.days;
>         }
> 
>     public IScroungerProvider getScroungerProvider()
>         {
>             return this.sp;
>         }
> 
>     public void setScroungerProvider(IScroungerProvider s)
>         {
>             this.sp = s;
>         }
> 
>     public void setRuleTypes(List<Long> l) throws Exception
>         {
>             this.ruleIPersonTypes = new ArrayList<IPersonType>(l.size());
>             Iterator<Long> typeIter = l.iterator();
>             while(typeIter.hasNext())
>             {
>  
> this.ruleIPersonTypes.add(this.getPersonProvider().getPersonType(typeIter.ne
> xt()));
>             }
>         }   public List<IPersonType> getRuleIPersonTypes()
>         {
>             return this.ruleIPersonTypes;
>         }
>     
>     public void setPersonProvider(IPersonProvider p)
>         {
>             this.ppp = p;
>         }
> 
>     public IPersonProvider getPersonProvider()
>         {
>             return ppp;
>         }
> 
>     public void setAuthProvider(IAuthProvider p)
>         {
>             this.authProvider = p;
>         }
> 
>     public IAuthProvider getAuthProvider()
>         {
>             return this.authProvider;
>         }
> 
>     public void setRuleId(Long id)
>         {
>             this.ruleId = id;
>         }
> 
>     public Long getRuleId()
>         {
>             return this.ruleId;
>         }
> 
>     /**
>      *
>      * @return {@link #SUCCESS}
>      */
>     public String execute() throws Exception
>         {
>             IScroungerRule rule =
> this.getScroungerProvider().getInstance();
>             rule.setRuleName(this.getRuleName());
>             rule.setId(this.getRuleId());
>             rule.setDays(this.getRuleDays());
>             rule.setRulePersonTypes(this.getRuleIPersonTypes());
> 
>             this.getScroungerProvider().makePersistent(rule);
>             this.setRule(rule);
>             
>             return SUCCESS;
>         }
> 
>     public void validate()
>         {
>             if(this.getRuleIPersonTypes() == null ||
> this.getRuleIPersonTypes().size() == 0)
>             {
>                 addActionError(getText("sc_no_type_selected"));
>             }
>             if(this.getRuleName() == null || this.getRuleName().length()
> ==
> 0)
>             {
>                 addActionError(getText("sc_no_rule_name_entered"));
>             }
>             
>             if(this.getRuleDays() == null)
>             {
>                 addActionError(getText("sc_no_rule_days_entered"));
>             }
>         }
>     
> }
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Stumped-on-form-field-tp22871959p22907970.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message