<h:form id="fObject">
<p:panel header="Manual Binding" styleClass="jeesl-panel">
<f:facet name="actions">
<j:svg type="jeeslSave" listener="#{jsonPropertyEditorBean.saveObject()}" update="@form" tooltip="#{msg.ttSave}"/>
</f:facet>
<j:inputGrid>
<p:outputLabel value="BaseDir"/>
<p:inputText value="#{jsonPropertyEditorBean.jsonObject.baseDir}"/>
<p:outputLabel value="Level"/>
<p:inputText value="#{jsonPropertyEditorBean.jsonObject.level}"/>
</j:inputGrid>
</p:panel>
<p:panel header="Json Object Result" styleClass="jeesl-panel">
<p>
<h:outputText value="#{jsonPropertyEditorBean.jsonObjectResult}"/>
</p>
</p:panel>
</h:form>
<h:form id="fJson">
<p:panel header="Json Magic" styleClass="jeesl-panel">
<f:facet name="actions">
<j:svg type="jeeslSave" listener="#{jsonPropertyEditorBean.saveJson()}" update="@form" tooltip="#{msg.ttSave}"/>
</f:facet>
<j:jsonPropertyEditor for="org.jeesl.model.json.io.fr.JsonFrFileSystem" value="#{jsonPropertyEditorBean.jsonString}"/>
</p:panel>
<p:panel header="Json Magic Result" styleClass="jeesl-panel">
<p>
<h:outputText value="#{jsonPropertyEditorBean.jsonString}"/>
</p>
</p:panel>
</h:form>
@Named @ViewScoped
public class JsonPropertyEditorBean extends AbstractJeeBean implements Serializable
{
final static Logger logger = LoggerFactory.getLogger(JsonPropertyEditorBean.class);
private static final long serialVersionUID = 1L;
private Map<String,Object> properties;
public Map<String,Object> getProperties() {return properties;}
public void setProperties(Map<String, Object> properties) {this.properties = properties;}
private List<String> propertyNames;
public List<String> getPropertyNames() {return propertyNames;}
public void setPropertyNames(List<String> propertyNames) {this.propertyNames = propertyNames;}
@PostConstruct
public void init()
{
super.initSecurity();
jsonObject = new JsonFrFileSystem();
jsonString = "";
// TODO @hh: I assume we can remove these properties?
properties = new HashMap<String, Object>();
propertyNames = new ArrayList<>();
for (PropertyDescriptor desc : PropertyUtils.getPropertyDescriptors(jsonObject))
{
if (desc.getWriteMethod() != null)
{
try
{
Object currentValue = desc.getReadMethod().invoke(jsonObject);
properties.put(desc.getName(), currentValue);
propertyNames.add(desc.getName());
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {e.printStackTrace();}
}
else
{
System.out.println("No SETTER available for property " +desc.getName() +" - skipping");
}
}
logger.info("Properties has " +properties.size() +" items: " +properties.toString());
}
private JsonFrFileSystem jsonObject;
public JsonFrFileSystem getJsonObject() {return jsonObject;}
public void setJsonObject(JsonFrFileSystem jsonObject) {this.jsonObject = jsonObject;}
private String jsonObjectResult;
public String getJsonObjectResult() {return jsonObjectResult;}
private String jsonString;
public String getJsonString() {return jsonString;}
public void setJsonString(String jsonString) {this.jsonString = jsonString;}
public void saveObject() throws JsonProcessingException
{
jsonObjectResult = JsonUtil.toPrettyString(jsonObject);
logger.info("JSON " +jsonObjectResult);
}
public void saveJson() throws JsonProcessingException
{
logger.info("JSON " +jsonString);
}
// TODO @hh: I assume we can remove this method?
public void process() throws JsonProcessingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
for (String propertyName : properties.keySet())
{
logger.info("Processing " +propertyName);
Object argument = new Object();
try {
argument = properties.get(propertyName);
if (argument!=null)
{
logger.info("Saving " +argument.toString());
// PropertyUtils.getPropertyDescriptor(jsonObject, prop).getWriteMethod().invoke(jsonObject, arguments);
SetterHelper.set(propertyName, jsonObject, argument);
}
}
catch (Exception e)
{
logger.error(e.getStackTrace().toString());
logger.error(e.getMessage());
}
}
saveObject();
}
// TODO @hh: I assume we can remove this method?
public void processComponent() throws JsonProcessingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
logger.info("Listener called after component logic triggered");
logger.info("JSON String after called: " +JsonUtil.toString(jsonObject));
}
}