2017-11-08 2 views
0

こんにちはデータベースのラジオボタンの値を更新しようとしています。 "Y"と "N"の2つのオプションがあります。私がNを選択すると、データベースでは "N"ではなくNULLに更新されます。java strutsデータベースのNの代わりにラジオボタンの値がNに更新されています

ここにコードがあります。

ExternalSystem.java

public class ExternalSystem extends ModelWritable { 
    private String externalSystemId; 
    private Boolean enabled; 

//getter/setter 
} 

ExternalSystemActionForm.java

public class ExternalSystemActionForm extends VistaActionForm { 
     private List<ExternalSystemDTO> externalSystems; 
     private String externalSystem; 
     // amend stuff 
     private String amendEnabled; 
     // authority 
     private Boolean hasAmendAuthority = Boolean.FALSE; 

     public List<ExternalSystemDTO> getExternalSystems() { 
      return externalSystems; 
     } 

     public void setAmendEnabled(String amendEnabled) { 
    this.amendEnabled = amendEnabled; 
} 

public String getAmendEnabled() { 
    return amendEnabled; 
} 
public Boolean getHasDeleteAuthority() { 
    return hasDeleteAuthority; 
} 

public void setHasAmendAuthority(Boolean hasAmendAuthority) { 
    this.hasAmendAuthority = hasAmendAuthority; 
} 
} 

ExternalSystemDispatchAction.java

public class ExternalSystemDispatchAction extends VistaDispatchActionBase { 

public ActionForward amend(ActionMapping mapping, ActionForm form, 
    HttpServletRequest request, HttpServletResponse response) throws Exception { 

    BrandMarketReferenceBusinessDelegate delegate = new 
BrandMarketReferenceBusinessDelegate(); 
    ExternalSystemActionForm actionForm = (ExternalSystemActionForm) form;  

    // Do 'Amend' Stuff 

    ExternalSystemDTO amendDTO = new ExternalSystemDTO(new ExternalSystem()); 
    amendDTO.setExternalSystemId(actionForm.getExternalSystem()); 

    amendDTO.setEnabled(actionForm.getAmendEnabled()); 
    amendDTO.setTimezoneName(actionForm.getAmendTimezone()); 

    actionForm.setErrorMessage(delegate.amendExternalSystem(amendDTO, getUser())); 


    populateCurrentData(delegate, actionForm); 
    for (ExternalSystemDTO dto : actionForm.getExternalSystems()) { 
     dto.setBeingAmended(false); 
    } 

    final ActionForward forward = mapping.findForward("success"); 

    return forward; 
} 
} 

ExternalSystemDTO.java

public class ExternalSystemDTO { 

private ExternalSystem externalSystem; 
private boolean isBeingAmended = false; 


public ExternalSystemDTO (ExternalSystem externalSystem) { 
    this.externalSystem = externalSystem; 
} 

public String getEnabled() { 
    return externalSystem.getEnabled() ? "Y" : "N"; 
} 

public void setEnabled(String enabled) { 
    externalSystem.setEnabled(enabled.equals("Y")); 
} 
} 

externalSystemMaint.jsp

<script> 
    function selectButton(externalSystem){ 
    document.forms.ExternalSystemForm.method.value="select"; 
    document.forms.ExternalSystemForm.externalSystem.value=externalSystem; 
    document.forms.ExternalSystemForm.submit(); 
} 

    function amendButton(externalSystem){ 
    document.forms.ExternalSystemForm.method.value="amend"; 
    document.forms.ExternalSystemForm.externalSystem.value=externalSystem; 
    document.forms.ExternalSystemForm.submit(); 
} 

</script> 


    <!-- This row has previously been selected for update so show data in a way that it can be amended --> 

    <logic:equal name="externalSystem" property="beingAmended" value="true"> 
     <logic:equal name="externalSystem" property="enabled" value="Y"> 
      <td class="borderedCell">Y<input name="amendEnabled" type="radio" value="Y" checked></input> 
     </logic:equal> 
     <logic:notEqual name="externalSystem" property="enabled" value="Y"> 
      <td class="borderedCell">Y<input name="amendEnabled" type="radio" value="Y"></input> 
     </logic:notEqual> 
     <logic:equal name="externalSystem" property="enabled" value="Y">    
      N<input name="amendEnabled" type="radio" value="N" ></input></td> 
     </logic:equal> 
     <logic:notEqual name="externalSystem" property="enabled" value="Y">    
      N<input name="amendEnabled" type="radio" value="N" checked></input></td> 
     </logic:notEqual> 
     <!-- Eventually make this a drop down based on the vista_external_system table -->    
     <td class="borderedCell"><input name="amendTimezone" type="text" value="<bean:write name="externalSystem" property="timezoneName"/>"></input></td> 
     <td class="borderedCell" align="center"> 
     <!-- In theory should not get this far if they haven't got authority but what the heck --> 
     <logic:equal name="ExternalSystemForm" property="hasAmendAuthority" value="true">    
      <html:img src="images/select2.gif" onclick='<%= "amendButton(" + MessageUtils.encodeJSConstant(externalSystem.getExternalSystemId()) + ")" %>' /> 
     </logic:equal> 

誰かがこれで私を助けてください。

答えて

0

ブラウザは、ラジオボタンのプロパティがcheckedの場合にのみ値を送信し、ラジオボタンのプロパティがuncheckedの場合は、を指定しないで、を送信します。

ラジオボタンのプロパティがuncheckedで、amendEnabledの値がnullの場合、セッターsetAmendEnabledが呼び出されないことを意味します。 amendEnabledのデフォルト値を割り当てるようにしてください:

public class ExternalSystemActionForm extends VistaActionForm { 
    ... 
    private String amendEnabled = "N"; 
+0

こんにちは@sergey答えをありがとう。 amendEnabled変数にデフォルト値を代入しようとしましたが、依然としてデータベースにNULL値を取得しています。 –

関連する問題