How can I fetch the table to my action class? When onclicking the button this function happens.
This is my action class:
public class Action {
ActionVO avo = new ActionVO();
ActoinForm af = new ActionFrom();
public string loaddata() {
if (af == null) {
PropertyUtils.copyProperties(ActionVO, ActionForm);
HashMap hmInput = new HashMap();
hmInput.put(APPCONSTANT.WORKFLOW_ID, APPCONSTANT.REQ_CODE);
hmInput.put(APPCONSTANT.INPUT_CRETERIA, avo);
rvo.execute(hmInput);
af.setSummaryList((Arraylist) rvo.getResultList());
request.setAttribute("setSummaryList", af.getSummaryList());
request.getSession().setAttribute("", ActionVO.getSummaryList());
return success;
}
}
}
Related
I have a JSP page wherein user has to enter some custom URL. I want to pass that custom url in #WebInitParam in my servlet
#WebServlet(name = "oauthCustomURL", initParams = {
#WebInitParam(name = "clientId", value = "123"),
#WebInitParam(name = "key", value = "***"),
#WebInitParam(name = "environment", value = "customUrl"),
}) //in value I want to pass the value entered by user
#WebInitParam's are used for the configuration of servlets implemented by third-party libraries. Usually, these libraries use methods getInitParameterNames() and getInitParameter() of abstract class GenericServlet (but you should check in library code for it).
For the dynamic setting of the #WebInitParam you can override those methods in your servlet implementation. Below is an example of how to do it.
#WebServlet(urlPatterns = "/abc/*")
public class DynamicInitParamServlet extends SomeCustomLibraryHttpServlet {
private static final String WEB_INIT_PARAM_NAME = "some.param.name";
private Integer webInitParamValue = null;
#Override
public void init(ServletConfig config) throws ServletException {
// calculate init param value dynamically,
// TODO: implement your own code
webInitParamValue = 2 * 3;
// call custom library servlet init after init parameter value is set
super.init(config);
}
#Override
public Enumeration<String> getInitParameterNames() {
if (webInitParamValue != null) {
final Set<String> initParameterNames = new HashSet<>(Collections.list(super.getInitParameterNames()));
initParameterNames.add(WEB_INIT_PARAM_NAME);
return Collections.enumeration(initParameterNames);
} else {
return super.getInitParameterNames();
}
}
#Override
public String getInitParameter(String name) {
if (WEB_INIT_PARAM_NAME.compareTo(name) == 0 && webInitParamValue != null) {
return "" + webInitParamValue;
} else {
return super.getInitParameter(name);
}
}
}
Hey guys am new to this and I would appreciate any help.
I want to call getListTenant() from my save function below and clear the list using iterator before doing my save. Below is the code in my controller:
package controllers;
public class TenantController extends AppController {
Tenant tenant;
FacilityUnit unit;
// list tenants in selected facility
public Result listTenant() {
return ok(Json.toJson(getTenantList()));
}
private List<Tenant> getTenantList() {
List<Tenant> tenants = Tenant.find
.fetch("unit.facility")
.where().eq("unit.facility", currentFacility())
.findList();
return tenants;
}
public Result saveTenant() {
JsonNode submissionNode = request().body().asJson();
JsonNode itemsArray = submissionNode.get("items");
//clear tenant
// create the new tenant
if (itemsArray.isArray()) {
for (JsonNode itemNode : itemsArray) {
JsonNode tenantNode = itemNode.get("tenant");
String tenantId = tenantNode.get("id").asText();
JsonNode unitNode = itemNode.get("unit");
String unitId = unitNode.get("id").asText();
System.out.println("##### Tenant ID IS " + tenantId);
System.out.println("##### unit ID IS " + unitId);
// Tenant.find.where().eq("tenant.id",
// tenant.getTenant().getId()).eq("unit.id", unit.getId()
// ).delete();
// Util.isNotEmpty() &&
if (Util.isNotEmpty(tenantId) && Util.isNotEmpty(unitId)) {
// these two are the minimal criteria for an tenant
Tenant tenant = new Tenant();
tenant.setTenant(Person.find.byId(tenantId));
tenant.setUnit(FacilityUnit.find.byId(unitId));
tenant.save();
System.out.println("##### SAVED A TENANT");
}
}
}
System.out.println("##### DONE");
return ok(infoMessage("Update of " + tenant.getTenant() + "successful"));
}
Iterate over the Tenants from getTenantList() and call delete() on them to clear them.
For example:
private List<Tenant> getTenantList() {
List<Tenant> tenants = Tenant.find
.fetch("unit.facility")
.where().eq("unit.facility", currentFacility())
.findList();
return tenants;
}
public Result saveTenant() {
// Do something...
// ...
// Get the tenants list that we want to clear before saving.
// Best way to do this is loop over it and call delete.
for (Tenant tenant : getTenantList()) {
tenant.delete();
}
// Do some more things...
// ...
}
NewForm.java
public class NewForm extends WebPage {
private Bean bean;
private DropDownClass dropdown;
private String selected = "choice";
void init()
{
bean = new Bean();
dropdown=new DropDownClass("test");
}
public NewForm(final PageParameters page) {
init();
final TextField<String> textname = new TextField<String>("name",Model.of(""));
textname.setRequired(true);
final DropDownChoice<String> dropname = new DropDownChoice<String>("type", new PropertyModel<String>(this, "selected"),
dropdown.getlist());
Form<?> form = new Form<Void>("Form") {
#Override
public void onSubmit() {
final String name = (String) textname.getModelObject();
final String dropdown = (String)dropname.getModelObject();
bean.add(name,dropdown);
final String schema = bean.getJsonSchema().toString();
page.add("schema", schema);
setResponsePage(new NewForm(page));
}
};
Label schemalabel = new Label("schema", page.get("schema"));
add(form);
form.add(textname);
form.add(dropname);
form.add(schemalabel);
}
}
Bean.java
public class Bean
{
private JSONObject jsonSchema;
public JSONObject getJsonSchema() {
return jsonSchema;
}
public void setJsonSchema(JSONObject jsonSchema) {
this.jsonSchema = jsonSchema;
}
public Bean() {
jsonSchema = new JSONObject();
}
public void add(String key,String value)
{
jsonSchema.put(key, value); // I am able to append values each time using "put" or "append" in JSF but not in WICKET.How can I append values in Wicket?
//or jsonSchema.append(key, value); //adding values only once and not appending each time,I enter the values in TextField and DropDown
}
}
In CreateForm.java - I have a Textfield and DropDown. When I enter the values in TextField and DropDown..I am able to convert the values entered in TextField and DropDown as JSON schema from method add(String key,String value) in AttributeInfo.java and display the schema as - {"name":"abc"} //where name is value entered in TextField and abc is from DropDown.
I am able to display the schema only once onSubmit But I need to append the values to schema each time,I enter in TextField and DropDown onSubmit and display in the samepage.
How can I achieve this in Wicket?
I am just a beginner.Any Help would be appreciated.Thankyou in advance.
I'm not sure if I understand correctly BeanFieldGroup but I hope it should bind values from fields(UI components) to my custom beans (eg POJOs).
Here I have my POJO.
public class JobConfigDTO {
#Max(50)
private String format;
#Max(50)
private String template;
#Max(50)
private String channel;
}
With this code I'm attempting to bind my POJO to checkboxes.
private void test(){
JobConfigDTO jobConfigDTO = new JobConfigDTO();
ComboBox comboChannel = createEditFormCombobox("Channel", "CHANNEL");
ComboBox comboFormat = createEditFormCombobox("Format", "FORMAT");
ComboBox comboTemplate = createEditFormCombobox("Template", "TEMPLATE");
BeanFieldGroup<JobConfigDTO> binder = new BeanFieldGroup<>(JobConfigDTO.class);
binder.setItemDataSource(jobConfigDTO);
binder.setBuffered(false);
binder.bind(comboChannel, "channel");
binder.bind(comboChannel, "channel");
binder.bind(comboFormat, "format");
binder.bind(comboTemplate, "template");
Button btnSave = new Button("Add");
btnSave.addClickListener(new Button.ClickListener() {
#Override
public void buttonClick(Button.ClickEvent event) {
try {
log.debug("jobconfigdto {}", jobConfigDTO);
binder.setBuffered(true);
log.debug("jobconfigdto {}", jobConfigDTO);
binder.commit();
binder.setBuffered(false);
} catch (FieldGroup.CommitException e) {
log.error("Unable to save job config", e);
}
}
});
}
When I set values for comboboxes in form and click add button pojo JobConfigDTO is not filled.
Am I missing something or BeanFieldGroup has another usage? I would like to bind values from checkboxes to my pojo class and validate them at the end.
i have one native select branchStateSelect:
branchStateSelect = new NativeSelect("State:");
branchStateSelect.setImmediate(true);
branchStateSelect.setWidth(COMMON_FIELD_WIDTH);
branchStateSelect.setRequired(true);
branchStateSelect.setNullSelectionItemId(0);
branchStateSelect.setItemCaption(0, "--Select--");
branchStateSelect.addValueChangeListener(fetchCityListener);
and there is another native select : this is binded to a fieldgroup
communicationAddressStateSelect = new NativeSelect("State:");
communicationAddressStateSelect.setRequired(true);
communicationAddressStateSelect.setImmediate(true);
communicationAddressStateSelect.setNullSelectionAllowed(true);
communicationAddressStateSelect.setWidth(COMMON_FIELD_WIDTH);
communicationAddressStateSelect.setEnabled(false);
and the city listener for state select :
private ValueChangeListener fetchCityListener = new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
if (event.getProperty().getValue() == null) {
//do nothing
}
else{
communicationAddressStateSelect.setNullSelectionItemId(0l
communicationAddressStateSelect.setItemCaption(0l,
"state1");
communicationAddressStateSelect.select(0l);
}
}
}}
}
};
when I select branchstateselect native select
the value in the communicationAddressStateSelect is populated
but value binded to the fieldgroup is null???? why>?>>>
I want value 0L to be binded... what is the error