TYPO3 Extbase: Assigning 2 different objects to the view? - typo3

I have a showAction in my Controller of the class "Termin" that not only assigns the object of that class to the view, but it should also pass a second object that is in relation to that object via the getter.
public function showAction(\...\Kundentermine\Domain\Model\Termin $termin)
{
$this->view->assign('termin', $termin);
$this->view->assign('kaufmnnisch', $termin->getZugewkaufmaennisch());
}
The corresponding template should not only show details for the "Termin" object, but also have a link to the show action of another Controller which i pass the second assigned object "kaufmnnisch" to.
<tr>
<td>
<f:link.action action="show" controller="Kaufmnnisch" arguments="{kaufmnnisch : kaufmnnisch}">
<f:translate key="tx_kundentermine_domain_model_termin.kaufmaennisch" />
</f:link.action>
{termin.kaufmaennisch}
</td>
<td>
</td>
</tr>
But i get an error:
Argument 1 passed to ...\Kundentermine\Controller\KaufmnnischController::showAction() must be an instance of ...\Kundentermine\Domain\Model\Kaufmnnisch, null given
Why is the object NULL? Testing "$termin->getZugewkaufmaennisch()" inside a va_dump() within the TerminController gets me the correct object, so why isn't the object assigned to the view?
Edit: As requested, here is the show Action of the Controller "Kaufmnnisch" that gets the object $kaufmnnisch, which supposedly is NULL on arrival, so to speak.
/**
* action show
*
* #param \...\Kundentermine\Domain\Model\Kaufmnnisch $kaufmnnisch
* #return void
*/
public function showAction(\...\Kundentermine\Domain\Model\Kaufmnnisch $kaufmnnisch)
{
$this->view->assign('kaufmnnisch', $kaufmnnisch);
}
Edit2: Problem solved...
The problem was that the object was assigned to the template, but from there it should have been passed to a partial as an argument. So it never arrived ath the point:
<tr>
<td>
<f:link.action action="show" controller="Kaufmnnisch" arguments="{kaufmnnisch : kaufmnnisch}">
<f:translate key="tx_kundentermine_domain_model_termin.kaufmaennisch" />
</f:link.action>
{termin.kaufmaennisch}
</td>
<td>
</td>
</tr>
Now, after i added it here:
<f:render partial="Termin/Properties" arguments="{termin:termin, kaufmnnisch:kaufmnnisch}" />
It works flawlessly.

Related

Lightning Web Component Reactive and Non Reactive Properties

I have a Lightning Web Component with 2 private properties. One property is reactive via track, and the second is non-reactive (not decorated).
This is the HTML file:
<template>
<table style="background: white;">
<tr>
<td>
Reactive Private Property:
<lightning-input type="text" onchange={reactiveHandler}></lightning-input>
Value: {reactiveProperty}
</td>
</tr>
<tr>
<td>
Nont-Reactive Private Property:
<lightning-input type="text" onchange={nonReactiveHandler}></lightning-input>
Value: {nonReactiveProperty}
</td>
</tr>
</table>
</template>
This is the JS file:
import { LightningElement, track } from 'lwc';
export default class ReactiveAndNonReactiveProperties extends LightningElement {
#track reactiveProperty;
nonReactiveProperty;
reactiveHandler(event) {
this.reactiveProperty = event.target.value;
}
nonReactiveHandler(event) {
this.nonReactiveProperty = event.target.value;
}
}
As you can see, only one property is decorated with #track. However, when I type something in the input text of the non-reactive property, it is still rendered on the screen, which should not happen until I change the value in the input text of the reactive property.
Correction in provided answer: According to Spring'20 release, all primitive properties are reactive by default, however, if the value held by property is either an array or an object, then you'll need to specify the property reactive using #track decorator
According to Spring'20 release , all properties are by default reactive. Even if you don't use "track" , it will be rendered on the screen.

(GWT) - Why doesn't my call to TableSectionElement.setInnerSafeHtml() get rendered to the DOM?

I have a legacy application that uses UIBinder to render the UI. I am trying to spit out records into a standard element. In my view.ui.xml file, I have a table with my semantic element setup and a element with the appropriate ui:field.
<table>
<thead>
<tr>
<th> </th>
<th>Customer #</th>
<!-- Shortened for brevity -->
</tr>
</thead>
<tbody ui:field="tbody"><!-- Note the ui:field defined -->
</tbody>
</table>
In my view.java class, I have that ui:field coupled to a TableSectionElement.
public class View extends Composite implements ViewPresenterInterface {
#UiField TableSectionElement tbody;
public TableSectionElement getTbody() {
return tbody;
}
}
In my class that handles rendering the table elements, the code is fairly straight-forward:
private void renderOrderTable() {
List<OrderToReviewProxy> sortedList = sortOrders(orders);
SafeHtmlBuilder sb = new SafeHtmlBuilder();
for(OrderToReviewProxy order : sortedList) {
sb.appendHtmlConstant("<tr>");
sb.appendHtmlConstant("<td>");
sb.appendEscaped(order.getCustomerNumber());
sb.appendHtmlConstant("</td>");
sb.appendHtmlConstant("</tr>");
}
view.getTbody().setInnerHTML(""); // Breakpoint A
view.getTbody().setInnerSafeHtml(sb.toSafeHtml()); // Breakpoint B
}
At Breakpoint A, inspecting view.getTbody() shows me the <tbody></tbody> element empty, as expected.
Stepping over Breakpoint B, inspecting view.getTbody() shows me the <tbody> element with the expected HTML that the SafeHtmlBuilder generated during the for loop.
However, when I look at the rendered page, the <tbody> element has no child nodes. None of the HTML from calling sb.toSafeHtml() seems to get written into the DOM. Can anyone help me out here? I have no idea why this isn't working.

AngularJS rows are displayed with empty data

I am testing out angularJS.
In app.js I have
function ListCtrl($scope, Restangular) {
Restangular.all("employee").getList().then(function(employee) {
$scope.employee = employee;
console.log($scope.employee.emp);
});
}
and in html I have
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Emp No</th>
<th>Name</th>
<th><i class="icon-plus-sign"></i></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee | filter:search | orderBy:'ename'">
<td>{{employee.empno}}
</td>
<td>{{employee.ename}}</td>
<td>
<i class="icon-pencil"></i>
</td>
</tr>
</tbody>
</table>
Problem I am facing is there are empty rows being displayed with no data being displayed.
What could be the reason for this?
Edit 1
JSON returned from server
{"emp":[{"empno":"7369","ename":"SMITH","hiredate":
"1980-12-17T00:00:00+03:00","job":"CLERK","mgr":"7902","sal":"800"},
{"comm":"300","empno":"7499","ename":"ALLEN","hiredate":
"1981-02-20T00:00:00+03:00","job":"SALESMAN","mgr":"7698","sal":"1600"},
{"comm":"500","empno":"7521","ename":"WARD","hiredate":
"1981-02-22T00:00:00+03:00","job":"SALESMAN","mgr":"7698","sal":"1250"},
{"empno":"7566","ename":"JONES","hiredate":
"1981-04-02T00:00:00+03:00","job":"MANAGER","mgr":"7839","sal":"2975"},
{"comm":"1400","empno":"7654","ename":"MARTIN","hiredate":
"1981-09-28T00:00:00+03:00","job":"SALESMAN","mgr":"7698","sal":"1250"},
{"empno":"7698","ename":"BLAKE","hiredate":
"1981-05-01T00:00:00+03:00","job":"MANAGER","mgr":"7839","sal":"2850"},
{"empno":"7782","ename":"CLARK","hiredate":
"1981-06-09T00:00:00+03:00","job":"MANAGER","mgr":"7839","sal":"2450"},
{"empno":"7788","ename":"SCOTT","hiredate":
"1987-04-19T00:00:00+03:00","job":"ANALYST","mgr":"7566","sal":"3000"},
{"empno":"7839","ename":"KING","hiredate":
"1981-11-17T00:00:00+03:00","job":"PRESIDENT","sal":"5000"},
{"comm":"0","empno":"7844","ename":"TURNER","hiredate":
"1981-09-08T00:00:00+03:00","job":"SALESMAN","mgr":"7698","sal":"1500"}]}
console log from chrome browser
[Object, Object, Object, Object, Object, Object, Object, Object,
Object, Object, Object, Object, Object, Object, route: "employee",
getRestangularUrl: function, addRestangularMethod: function, one:
function, all: function…]
0: Object
empno: "7369"
ename: "SMITH"
hiredate: "1980-12-17T00:00:00+03:00"
job: "CLERK"
mgr: "7902"
sal: "800"
Based on the JSON you've included it looks like $scope.employee should contain a one key called "emp", which is what you print to the console. You might need to change your ng-repeat to work with that.
Also, I'm unfamiliar with the form of your ng-repeat expression. I believe they are supposed to follow a form similar to "something in somethings" so in this case instead of just employee you may want that to be employee in employee.emp.
In a more general sense, the Angular Batarang plugin for Chrome is infinitely helpful for solving these sorts of problems.

Spring form:radiobuttons : map<Object, Enum>: reference key in radiobutton-path in order to set value?

I have a Map<Course, Role> courses belonging to the command object user and I want to select a role from roles[enum array] = Role.values for each course in the keyset. I populate the entries with all the courses I want and a default role and put this in the user in the model. Below is my form, but I can't figure out how to refer to the key (which is "course") for the map
<form:form method="POST" commandName="user">
<table>
<tr>
<td>User Name:</td>
<td><form:input path="name" /></td>
</tr>
<c:forEach var="course" items="${courseChoices}">
<tr>
<form:radiobuttons path="courses['${course}']" items="${roles}"/>
</tr>
</c:forEach>
</table>
<input type="submit" value="save changes">
<form:errors path="*" />
</form:form>
I have a propertyeditor bound to convert Course to String and back, which simply uses the entity id.
I am getting
InvalidPropertyException:
Invalid property 'courses[com.example.app.Course#7]' of bean class [com.example.app.User]:
Invalid index in property path 'courses[com.example.app.Course#7]';
nested exception is org.springframework.beans.TypeMismatchException:
Failed to convert property value of type 'java.lang.String' to required type 'com.example.app.Course' for property 'null';
nested exception is java.lang.NumberFormatException: For input string: "com.example.app.Course#7"
I don't know what is null, because I can see the Course with id 7 in my database.
Fundamentally, what is evaluating the path attribute and how does it understand the jsp context? Is this Spring expression language? I've been looking for resources to figure out how to pick values for my map keys from my set of roles, but I haven't found much.
I suppose you have a getter getId() or something similar in courses so instead of path="courses['${course}']" in the radiobuttons tag write path="courses['${course.id}']" (or course.whateverTheIdIsCalled for an id getter getWhateverTheIdIsCalled())

Issue Binding AutoPopulating List to a form Spring MVC

I have an issue binding the AutoPupulating List in a form to update the data. I was able to save the data using Autopopulating list though.
Here is the form backing model.
public class AddUpdateShot {
private Integer shootId;
private char shotSelect;
private String shotNotes;
private Integer numOfItems;
private AutoPopulatingList itemNumColors;
private Integer totalNumOfItems;
private String shotName;
----------
public void setItemNumColors(AutoPopulatingList itemNumColors){
this.itemNumColors = itemNumColors;
}
public AutoPopulatingList getItemNumColors(){
return this.itemNumColors;
}
--------
}
Where itemNumClors is a simple model
public class ItemNumColor {
private Integer id;
private Integer itemNum;
private String itemName;
private String colorCode;
private String colorName;
------get and set methods
}
When I first saved the data, depending on how many ItemColors the user wanted,using jquery I added the input fields dynamically as shown in the following code.
<form:form id="createShootForm" method="POST"
commandName="createShoot">
<tr>
<td align="left"><label for="shootName">*Shoot Name:</label></td>
<td><form:input id="shootName" class="required" path="shootName" /></td>
</tr>
------- other input fields in form backing obj----
<c:forEach var="i" begin="${start}" end="${end-1}" step="1" varStatus="status">
<tr>
<td align="left"><label for="itemNumber${i}">Item
Number${i+1}:</label></td>
<td><form:input id="itemNumber${i}"
path="createShoot.itemNumColors[${i}].itemNum" /></td>
<td><form:select id="color${i}"
path="createShoot.itemNumColors[${i}].colorCode">
<form:option value="" label="Color" />
</form:select>
</td>
</tr>
</c:forEach>
<tr id="submitRow">
<td></td>
<td></td>
<td align="right"><input name="submit" type="submit" value="Next" /></td>
</tr>
</table>
</form:form>
The above code worked perfectly fine when I initially saved the data. But now when the user want to update the earlier saved data, I am unable to bind the Autopopulating list to the JSP. Here is how am doing it.
<form:form id="updateShotForm" method="POST"
commandName="shotToUpdate">
----other input fields of form backing object---
<c:forEach var="i" begin="0" end="${totalNumOfItems-1}" step="1"
varStatus="status">
<tr><td align="left"><label for="itemNumber${i}">ItemNumber${i+1}:</label></td>
<td><form:input id="itemNumber${i}"path="shotToUpdate.itemNumColors[${i}].itemNum" /></td>
</tr>
</c:forEach>
<tr id="submitRow">
<td></td>
<td></td>
<td align="right"><input name="submit" type="submit"
value="Next" />
</td>
</table>
</form:form>
When I open the edit JSP, I get the following run time exception
Sep 7, 2011 10:38:00 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jalapeno] in context with path [/OnLocation] threw exception [An exception occurred processing JSP page /WEB-INF/views/app/updateShot.jsp at line 256
253: <tr>
254: <td align="left"><label for="itemNumber${i}">Item
255: Number${i+1}:</label></td>
256: <td><form:input id="itemNumber${i}"
257: path="shotToUpdate.itemNumColors[${i}].itemNum" /></td>
258: <td><form:select id="color${i}"
259: path="shotToUpdate.itemNumColors[${i}].colorCode">
Stacktrace:] with root cause
org.springframework.beans.NotReadablePropertyException: Invalid property 'shotToUpdate' of bean class [com.jcrew.jalapeno.app.model.AddUpdateShot]: Bean property 'shotToUpdate' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:707)
at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:555)
at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:532)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:697)
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:98)
at org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:224)
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:160)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:123)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:408)
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:140)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
I am not sure why I am not able to bind the object this way to the form since my form backing object does have an Autopopulating List which I initialised in the controller before loading this form
AutoPopulatingList itemNumColors = new AutoPopulatingList(ItemNumColor.class);
for( OnLocShotItemNumber onLocItemNumColor : itemNumColorsList){
ItemNumColor itemColor = new ItemNumColor();
itemColor.setId(onLocItemNumColor.getId());
itemColor.setColorCode(onLocItemNumColor.getItemColorCode());
itemColor.setItemNum(onLocItemNumColor.getItemNumber());
itemNumColors.add(itemColor);
}
shotToUpdate.setItemNumColors(itemNumColors);
model.put("shotToUpdate", shotToUpdate);
model.put("totalNumOfItems", itemNumColorsList.size());
Any help is greatly appreciated.
Thanks,
Shravanthi
Remove the 'shotToUpdate.' keyword from the PATH attribute. You have already specified the command object name so the PATH attributes should be relative to the command object.